package com.honey.service;

import org.java.plugin.Plugin;
import org.java.plugin.PluginLifecycleException;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.Field;
import com.honey.compilation.java.InnerClass;
import com.honey.compilation.java.InnerEnum;
import com.honey.compilation.java.Method;
import com.honey.compilation.java.StaticBlock;
import com.honey.core.compiler.ContentType;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.generator.PresentationLayerCompilation;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.utils.ObjectFactory;
import com.honey.generator.java.GeneratorBusinessLayerCompilation;
import com.honey.generator.java.GeneratorJavaClassPlugin;
import com.honey.generator.java.extension.point.GeneratorJavaClass;
import com.honey.service.field.ServiceField;
import com.honey.service.method.ServiceMethod;

public class SampleServiceExtension extends GeneratorBusinessLayerCompilation{
	
	private SampleServicePlugin sSampleServicePlugin = null; 
	
	private PresentationLayerCompilation presentationLayer = null;
	
	private GeneratorJavaClassPlugin generatorJavaClassPlugin = null; 
	
	public SampleServiceExtension(Plugin belongPlugin) {
		super(belongPlugin);
		sSampleServicePlugin = (SampleServicePlugin)belongPlugin;
		try {
			 generatorJavaClassPlugin = ( GeneratorJavaClassPlugin )ObjectFactory.getRequestPlugin(belongPlugin, "honey.generator.java.plugin");
		} catch (PluginLifecycleException e) {
			e.printStackTrace();
		}
	}

	@Override
	public GeneratorJavaClass[] getGeneratorJavaClass() {
		return new GeneratorJavaClass[]{
				new SampleService(false),
				new SampleService(true),
		};
	}

	@Override
	public GeneratorJavaClassPlugin getGeneratorJavaClassPlugin() {
		return generatorJavaClassPlugin;
	}
	
	@Override
	public void setPresentationLayerCompilation(PresentationLayerCompilation presentationLayer) {
		this.presentationLayer = presentationLayer;
	}

	@Override
	public Method[] layerPublicMethod() {
		return null;
	}
	
	@Override
	public FullyQualifiedJavaType layerType() {
		return null;
	}
	
	private class SampleService implements GeneratorJavaClass{
		
		private boolean isInterface = false ;
		
		private AbstractJavaCompilation abstractJavaCompilation = null;
		public SampleService( boolean isInterface  ){
			this.isInterface = isInterface;
		}
		
		@Override
		public AbstractJavaCompilation createNewCompilation(
				IntrospectSchema introspectSchema,
				IntrospectSchemaColumn introspectSchemaColumn) {
			return new ServiceClass(sSampleServicePlugin, presentationLayer, isInterface).createClass(introspectSchema, introspectSchemaColumn);
		}

		@Override
		public FullyQualifiedJavaType getType() {
			return abstractJavaCompilation.getType();
		}
		
		@Override
		public ContentType getContentType() {
			return null;
		}
		
		@Override
		public Field[] importFields() {
			Field[] answer = null;
			if( !isInterface ) answer =new Field[]{
				(new ServiceField(sSampleServicePlugin,presentationLayer)).createField(),
			};
			return  answer ;
		}

		@Override
		public FullyQualifiedJavaType[] importImportClass() {
			return new FullyQualifiedJavaType[]{
				presentationLayer.layerType(),
			} ;
		}

		@Override
		public InnerClass[] importInnerClass() {
			
			return null;
		}

		@Override
		public InnerEnum[] importInnerEnumClass() {
			
			return null;
		}

		@Override
		public Method[] importMethods() {
			return new ServiceMethod(sSampleServicePlugin,presentationLayer).createMethod();
		}

		@Override
		public StaticBlock[] importStaticBlocks() {
			
			return null;
		}
	}

	@Override
	public FullyQualifiedJavaType[] requestClass() {
		
		return null;
	}
}
